const { floor } = require("lodash");

/**
 * @param {number[]} numbers
 * @return {number}
 */
var minArray = function (numbers) {
  let res = Infinity;
  for (let i = 0; i < numbers.length; i++) {
    if (numbers[i] < res) {
      res = numbers[i];
    }
  }
  return res;
};

// 使用二分，需要注意的是数组中可能会出现重复元素，所以要去重
/**
 * @param {number[]} numbers
 * @return {number}
 */
var minArray = function (numbers) {
  let l = 0,
    r = numbers.length - 1;
  while (l < r) {
    let mid = Math.floor((l + r) / 2);
    //只要右边比中间大，那右边一定是有序数组
    if (numbers[r] > numbers[mid]) {
      r = mid;
    } else if (numbers[r] < numbers[mid]) {
      l = mid + 1;
      //去重
    } else r--;
  }
  return numbers[l];
};
